﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MultiAnnotatedRegex.parser {
	class Lexer {
		public IEnumerable<Token> Scan(IEnumerable<char> input) {
			int pos = 0;
			foreach (char c in input) {
				TokenType type;
				switch (c) {
					case '+': type = TokenType.Plus; break;
					case '*': type = TokenType.Star; break;
					case '?': type = TokenType.Question; break;
					case '(': type = TokenType.LeftParen; break;
					case ')': type = TokenType.RightParen; break;
					case '[': type = TokenType.LeftBrace; break;
					case ']': type = TokenType.RightBrace; break;
					case '{': type = TokenType.LeftCurly; break;
					case '}': type = TokenType.RightCurly; break;
					case '^': type = TokenType.Caret; break;
					case '$': type = TokenType.Dollar; break;
					case '|': type = TokenType.Or; break;
					case '.': type = TokenType.Dot; break;
					case ',': type = TokenType.Comma; break;
					case '\\': type = TokenType.Escape; break;
					default: type = TokenType.Literal; break;
				}
				yield return new Token(pos, type, c);
				pos++;
			}
			yield return new Token(pos, TokenType.End, '\0');
		}
	}
}
